package com.school.controller;

import com.school.entity.Orders;
import com.school.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/Orders")
public class OrdersController {
    @Autowired
    OrdersService service;

    // HttpServletRequest request, HttpServletResponse response

    @ResponseBody
    @RequestMapping("/getAll.do")
    public Orders[] getAll(String user_phone) {
        Orders[] orders = service.selectAll(user_phone);
        return orders;
    }

    @ResponseBody
    @RequestMapping("/insertOne.do")
    public boolean insertOne(int order_id, String user_phone, String ticket_id) {
        Orders order = new Orders(order_id, user_phone, ticket_id);
        int i = service.insertOne(order);
        if (i != 1) {
            return false;
        }
        return true;
    }

    @ResponseBody
    @RequestMapping("/deleteOne.do")
    public boolean deleteOne(String ticket_id) {
        System.out.println(" Orders ticket_id = " + ticket_id);
        int i = service.deleteOne(ticket_id);
        System.out.println("i = " + i);
        if (i != 1) {
            return false;
        }
        return true;
    }


}
